/*
 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, Hardware
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "gtest/gtest.h"
#include "pipeline/rs_modifiers_draw_thread.h"

using namespace testing;
using namespace testing::ext;

namespace OHOS::Rosen {
class RSModifiersDrawThreadTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;
protected:
    RSModifiersDrawThreadTest *rSModifiersDrawThread;
};

void RSModifiersDrawThreadTest::SetUpTestCase() {}
void RSModifiersDrawThreadTest::TearDownTestCase() {}
void RSModifiersDrawThreadTest::SetUp() {
    RSModifiersDrawThread = new RSModifiersDrawThread();
}
void RSModifiersDrawThreadTest::TearDown() {
    delete RSModifiersDrawThread;
}

/**
 * @tc.name: GetInstanceTest001
 * @tc.desc: test results of Instance
 * @tc.type:FUNC
 * @tc.require: issueIBH928
 */

HWTEST_F(RSModifiersDrawThreadTest, GetInstanceTest001, TestSize.Level1)
{
    ASSERT_EQ(&RSModifiersDrawThread::Instance(), &RSModifiersDrawThread::Instance());
}

/**
 * @tc.name: SetCacheDir001
 * @tc.desc: test results of SetCacheDir001
 * @tc.type:FUNC
 * @tc.require: issueIBH928
 */

HWTEST_F(RSModifiersDrawThreadTest, SetCacheDir001, TestSize.Level1)
{
    const std::string shaderCacheDir_ = "/path/shadercachedir";
    RSModifiersDrawThread::Instance().SetCacheDir(shaderCacheDir_);
    ASSERT_EQ(shaderCacheDir_, RSModifiersDrawThread::Instance().GetCacheDir());
}

/**
 * @tc.name: GetCacheDir001
 * @tc.desc: test results of GetCacheDir001
 * @tc.type:FUNC
 * @tc.require: issueIBH928
 */

HWTEST_F(RSModifiersDrawThreadTest, GetCacheDir001, TestSize.Level1)
{
    const std::string shaderCacheDir_ = "/path/shadercachedir";
    RSModifiersDrawThread::Instance().SetCacheDir(shaderCacheDir_);
    ASSERT_EQ(RSModifiersDrawThread::Instance().GetCacheDir(), shaderCacheDir_);
}

/**
 * @tc.name: Start001
 * @tc.desc: test results of GetCacheDir001
 * @tc.type:FUNC
 * @tc.require: issueIBH928
 */

HWTEST_F(RSModifiersDrawThreadTest, Start001, TestSize.Level1)
{
    rSModifiersDrawThread->Start();
    ASSERT_TRUE(rSModifiersDrawThread->isStarted_);
    rSModifiersDrawThread->Start();
    ASSERT_TRUE(rSModifiersDrawThread->isStarted_);
    ASSERT_NE(nullptr, rsModifiersDrawThread->runner_);
}

/**
 * @tc.name: PostTask001
 * @tc.desc: test results of PostTask001
 * @tc.type:FUNC
 * @tc.require: issueIBH928
 */

HWTEST_F(RSModifiersDrawThreadTest, PostTask001, TestSize.Level1)
{
    rsModifiersDrawThread->PostTask([]() {});
    ASSERT_EQ(rsModifiersDrawThread->isStarted_, true);
}

/**
 * @tc.name: PostTask002
 * @tc.desc: test results of PostTask002
 * @tc.type:FUNC
 * @tc.require: issueIBH928
 */

HWTEST_F(RSModifiersDrawThreadTest, PostTask002, TestSize.Level1)
{
    rsModifiersDrawThread->Start();
    rsModifiersDrawThread->PostTask([]() {});
    ASSERT_NE(rsModifiersDrawThread->handler_, nullptr);
}

/**
 * @tc.name: ScheduleTask001
 * @tc.desc: test results of ScheduleTask001
 * @tc.type:FUNC
 * @tc.require: issueIBH928
 */

HWTEST_F(RSModifiersDrawThreadTest, ScheduleTask001, TestSize.Level1)
{
    auto task = []() { /* some task */};
    auto future = rSModifiersDrawThread->ScheduleTask(task);
    ASSERT_EQ(future.valid(), true);
}